﻿Imports DTO
Imports DAO
Imports BUS

Public Class frmDangKi
    Dim dk As New DangNhapDTO
    Dim dkdao As New DangNhapDAO
    Dim dkbus As New DangNhapBUS
    Private Sub frmDangKi_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        loadtk()
        loadcbnv()
        loadcbloai()
    End Sub
    Private Sub loadcbloai()
        cbb_loai.DataSource = dkbus.loadtk()
        cbb_loai.DisplayMember = "Quyen"
        cbb_loai.ValueMember = "Quyen"
    End Sub
    Private Sub loadcbnv()
        Dim ncbus As New NhanVienBUS()
        cbb_nv.DataSource = ncbus.Loadnv()
        cbb_nv.DisplayMember = "MaNV"
        cbb_nv.ValueMember = "MaNV"
    End Sub
    Private Sub loadtk()
        dgv_tk.DataSource = dkbus.loadtk()
    End Sub

    Private Sub btn_them_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_them.Click
        If txt_hoten.Text <> "" And txt_pass.Text <> "" And txt_sdt.Text <> "" And txt_TenDN.Text <> "" Then
            Dim pxdto As New DangNhapDTO()
            pxdto.TenDN = txt_TenDN.Text
            pxdto.MatKhau = txt_pass.Text
            pxdto.MaNhanVien = Integer.Parse(cbb_nv.SelectedValue)
            pxdto.HoTenNhanVien = txt_hoten.Text
            pxdto.SDT = txt_sdt.Text
            pxdto.Quyen = Integer.Parse(cbb_loai.SelectedValue)
            DangNhapBUS.THEM(pxdto)
            loadtk()
            MessageBox.Show("Da Them Thanh Cong!", "Thong Bao")
        Else
            MessageBox.Show("Xin Nhập Đầy ĐỦ thông Tin", "Thông Bao")
        End If

    End Sub

    Private Sub btn_thoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_thoat.Click
        Me.Close()
        frmMain.Show()
    End Sub

    Private Sub btn_Nhaplai_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Nhaplai.Click
        txt_hoten.Text = ""
        txt_pass.Text = ""
        txt_sdt.Text = ""
        txt_TenDN.Text = ""
        cbb_loai.Text = ""
    End Sub

    Private Sub btn_xoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_xoa.Click
        Dim dial = MessageBox.Show("Bạn Có Thật Sự Muốn Xóa Nhà Cung Cấp Này?", "Hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If dial = DialogResult.Yes Then
            Dim nv As New DangNhapDTO()
            Dim ma As String
            ma = dgv_tk.Rows(temp).Cells(0).Value
            nv.TenDN = ma
            DangNhapBUS.XOA(nv)
            loadtk()
            MessageBox.Show("Da Xoa Thanh Cong!")
        End If
    End Sub
    Dim temp As Integer
    Private Sub dgv_tk_RowEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv_tk.RowEnter
        temp = e.RowIndex
    End Sub
End Class